<template>
  <div class="home-new" ref="target">
    <HomePanel title="新鲜好物" sub-title="新鲜出炉 品质靠谱">
         <!-- 具名插槽 -->
      <template #right><XtxMore path="/" /></template>
      <!-- 面板内容 -->
        <!-- 默认插槽 - 面板内容 -->
         <!-- 😂 transition 可以写注释，Transition 写了注释会警告 -->
      <transition name='fade'>
          <ul class="goods-list" v-if="list.length">
        <li v-for="goods in list" :key="goods.id">
          <RouterLink  :to="`/product/${goods.id}`">
            <img v-src="goods.picture" alt="" >
            <p class="name ellipsis">{{goods.name}}</p>
            <p class="price">&yen;{{goods.price}}</p>
          </RouterLink>
        </li>
      </ul>
        <HomeSkeleton v-else />
      </transition>
    </HomePanel>
  </div>
</template>
<script>
// import { ref } from 'vue'
import HomePanel from './home-panel.vue'
import { findNew } from '@/api/home'
import HomeSkeleton from './home-skeleton.vue'
// 导入数据懒加载函数
import { useLazyData } from '@/hooks/index'
// import { useIntersectionObserver } from '@vueuse/core'
export default {
  components: { HomePanel, HomeSkeleton },
  name: 'HomeNew',
  setup () {
    // 函数调用后返回的响应式数据可用于模板绑定
    const { target, list } = useLazyData(findNew)
    return { target, list }
  }
}
</script>
<style scoped lang="less">
.goods-list {
  display: flex;
  justify-content: space-between;
  height: 406px;
  li {
    width: 306px;
    height: 406px;
    background: #f0f9f4;
    .hoverShadow();
    img {
      width: 306px;
      height: 306px;
    }
    p {
      font-size: 22px;
      padding: 12px 30px 0 30px;
      text-align: center;
    }
    .price {
      color: @priceColor;
    }
  }
}
</style>
